from typing import Optional


class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
class Solution:
    def btreeGameWinningMove(self, root: Optional[TreeNode], n: int, x: int) -> bool:
        xnode = None
        def countSubStreeSize(node :Optional[TreeNode]):
            if node == None:
                return 0
            if node.val == x:
                nonlocal xnode
                xnode = node
            return 1 + countSubStreeSize(node.left) + countSubStreeSize(node.right)
        countSubStreeSize(root)
        left_all = countSubStreeSize(xnode.left)
        if left_all >= (n+1)/2:
            return True
        right_all = countSubStreeSize(xnode.right)
        if right_all >= (n+1)/2:
            return True
        other_all = n - right_all - left_all-1
        if other_all >= (n+1)/2:
            return True
        return False
            



